<?php
/*
 * File testWS_Leerling_GetCursussen.php for project Rijlesplanner.nl
 * Created on 1 dec 2007 at 01:02:57 by Ivar Pruijn
 */
require_once PEAR_DIR . '/PHPUnit/Framework.php';

require_once ("../modules/authentication.php");

class Leerling_GetCursussenTest extends PHPUnit_Framework_TestCase {
	private $config;
	private $template;
	private $wsclient;
	private $logger;

	public function setUp() {
		$this->config = $_SESSION['config'];
		require_once PEAR_DIR . 'Log.php';
		//$logger = &Log::singleton('win', 'LogWindow', 'Rijlesplanner', array('title' => 'Log Output'));
		$logger = & Log :: singleton('firebug', '', 'Rijlesplanner.nl', array (
			'buffering' => true,
			'timeFormat' => '%b %d %H:%M:%S'
		), PEAR_LOG_DEBUG);
		$this->logger = $logger;
		// templating
		$smarty = new Smarty_Rijlesplanner();
		$this->template = $smarty;
		$this->wsclient = new SoapClient($this->config['dashboard_wsdl'], array (
			'trace' => 1,
			'classmap' => array (
				'Leerling' => "Leerling"
			)
		));
	}

	public function testCursussen() {

		$auth = new Authentication();
		$auth->configure(array (
			"config" => $this->config,
			"logger" => $this->logger,
			"template" => $this->template,
			"wsclient" => $this->wsclient
		));

		$_POST['rijschool'] = 'dation';
		$_POST['email'] = 'test';
		$_POST['password'] = 'test';

		if ($auth->login()) {
			$sessionId = $_SESSION['SessionId'];
			$user = $_SESSION['user'];
			try {
				$result = $this->wsclient->WS_Leerling_GetCursussen(array (
					'RijschoolId' => $user->getRijschoolId(),
					'SessionId' => $sessionId,
					'LeerlingId' => $user->getId()
				));
				$this->logger->log($result, PEAR_LOG_DEBUG);
			} catch (SoapFault $e) {
				echo "SOAP Fault: (faultcode: {$e->faultcode} faultstring: {$e->faultstring})";
				var_dump($this->wsclient);
			}
		} else {
			echo "<h1>Could not log in</h1>";
			var_dump($this->wsclient);
		}
	}
}
?>
